package logic

import (
	"boxy-fresh/boxyrpc/boxyrpc"
	"boxy-fresh/boxyrpc/internal/svc"
	"boxy-fresh/models/mysql"
	"context"
	"time"

	"github.com/zeromicro/go-zero/core/logx"
)

type BoxyListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBoxyListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BoxyListLogic {
	return &BoxyListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BoxyListLogic) BoxyList(in *boxyrpc.BoxyListRequest) (*boxyrpc.BoxyListResponse, error) {
	// todo: add your logic here and delete this line

	var products []mysql.Product

	var ProductList []*boxyrpc.BoxyList

	for _, product := range products {
		list := boxyrpc.BoxyList{
			Name:        product.Name,
			Price:       float32(product.Price),
			Description: product.Description,
			ClassId:     int64(product.ClassId),
			CreatedAt:   product.CreatedAt.Format(time.DateTime),
		}
		ProductList = append(ProductList, &list)
	}

	return &boxyrpc.BoxyListResponse{
		List: ProductList,
	}, nil
}
